package dao;

import entity.AnimalCategory;
import util.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class AnimalCategoryDao {

    // 查询所有动物分类
    public List<AnimalCategory> getAllAnimalCategories() {
        List<AnimalCategory> categories = new ArrayList<>();
        String sql = "SELECT * FROM animal_category";
        try (Connection connection = JDBCUtils.getConnection();
             PreparedStatement preparedStatement = connection.prepareStatement(sql);
             ResultSet resultSet = preparedStatement.executeQuery()) {

            while (resultSet.next()) {
                int categoryId = resultSet.getInt("category_id");
                String categoryName = resultSet.getString("category_name");
                String description = resultSet.getString("description");

                AnimalCategory category = new AnimalCategory(categoryId, categoryName, description);
                categories.add(category);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return categories;
    }
}
